package com.srxz.personnelsystem.system.controller;

import com.srxz.personnelsystem.system.mapper.dto.LoginInfoDTO;
import com.srxz.personnelsystem.system.service.SysService;
import com.srxz.personnelsystem.util.BackMessage;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @作者：wgchao
 * @时间：19:23 2019/1/22 0022
 * @用途：系统操作-登录、注册、注销
 **/
@RestController
public class SysController {
    @Autowired
    private SysService sysService;

    /**
     * 登录
     * @param uname 用户名
     * @param password 密码
     * @return 登录用户信息
     */
    @GetMapping("/login")
    public BackMessage login(String uname, String password){
        if(StringUtils.isEmpty(uname)){
            return BackMessage.error("账户名不能为空");
        }
        if(StringUtils.isEmpty(password)){
            return BackMessage.error("密码不能为空");
        }

        return sysService.login(uname, password);
    }

    @PostMapping("/personnel/sys/logininfo")
    public BackMessage saveLoginInfo(@RequestBody LoginInfoDTO loginInfoDTO){
        if(StringUtils.isEmpty(loginInfoDTO.getUname()) || StringUtils.isEmpty(loginInfoDTO.getPassword())){
            return BackMessage.error("账户、密码不能为空");
        }
        return sysService.saveLoginInfo(loginInfoDTO);
    }
}
